<template>
    <Input v-model="inputValue" :placeholder="placeholder" :disabled="disabled" @on-blur="inputFun"
           :maxlength="maxlength"/>
</template>

<script>
    export default {
        name: "c-blank-input",
        props: {
            placeholder: {
                type: String,
                default: '请输入'
            },
            maxlength: {
                type: Number,
                default: 100
            },
            value: {
                type: String,
                default: ''
            },
            disabled: {
                type: Boolean,
                default: false,
            }
        },
        data() {
            return {
                inputValue: this.value
            }
        },
        watch: {
            value: function () {
                this.inputValue = this.value;
            }
        },
        model: {
            prop: 'value',
            event: 'change'
        },
        methods: {
            inputFun(e) {
                var value = this.inputValue;
                value = value.replace(/\ +/g, "");    // 去除 空格
                value = value.replace(/[\r\n]/g, "");    // 去除 换行符
                value = value.trim(); // 去除 前后空格
                this.inputValue = value;
                this.$emit('change', value)
            }
        }
    }
</script>

<style scoped>

</style>